//
//  BCIndustryAllCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/21.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "BCIndustryAllCell.h"
//
#import "CustomProjectContentView.h"


static CGFloat BCIndustryAllCellSeparatorHeight = 10.0f;

@interface BCIndustryAllCell ()

@property (nonatomic, strong) CustomProjectContentView *customContentView;

@end

@implementation BCIndustryAllCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    UIEdgeInsets contentEdgeInsets = [self.class contentEdgeInsets];
    CGFloat contentHeight = [CustomProjectContentView defaultHeightWithEdgeInsets:contentEdgeInsets];
    self.customContentView = [[CustomProjectContentView alloc] initWithContentEdgeInsets:contentEdgeInsets];
    [self.contentView addSubview:self.customContentView];
    [self.customContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self);
        make.height.mas_equalTo(contentHeight);
    }];
    //
    [self addSubview:self.separatorLine];
    self.separatorLine.backgroundColor = [UIColor separatorViewColor];
    [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(self);
        make.height.mas_equalTo(BCIndustryAllCellSeparatorHeight);
    }];
    //
    UITapGestureRecognizer *tapCollection = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCollectionAction)];
    [self.customContentView.displayCollection addGestureRecognizer:tapCollection];
}

- (void)setCellData:(BCProjectModel *)cellData {
    _cellData = cellData;
    //
    self.customContentView.contentData = cellData;
}


- (void)tapCollectionAction {
    if (self.tableView) {
        if (self.tableView.delegate && [self.tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
            [self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[self.tableView indexPathForCell:self]];
        }
    }
}

+ (UIEdgeInsets)contentEdgeInsets {
    return UIEdgeInsetsMake(22, 22, 20, 22);
}
+ (CGFloat)defaultHeight {
    CGFloat height = 0;
    UIEdgeInsets contentEdgeInsets = [self contentEdgeInsets];
    CGFloat contentHeight = [CustomProjectContentView defaultHeightWithEdgeInsets:contentEdgeInsets];
    height += contentHeight;
    height += BCIndustryAllCellSeparatorHeight;
    return 200.0f;
}

@end
